package projectwork.shchuangge.cn.com.newproject.uitls;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;

public class PackageUtil {

	//获取版本名
	public static String getVersionName(Context context, String packageName){
		//包管理器
				PackageManager packageManager = context.getPackageManager();
				//参数一：要获取谁的信息就传谁的包名，参数二：标记,获取什么数据就给什么标记，给0，只获取最基本信息
				try {
					PackageInfo packageInfo = packageManager.getPackageInfo(packageName, 0);
					String versionName = packageInfo.versionName;
					return versionName;
				} catch (NameNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
				return "未知版本";
	}
	//获取版本号
	public static int getVersionCode(Context context, String packageName){
		//包管理器
				PackageManager packageManager = context.getPackageManager();
				//参数一：要获取谁的信息就传谁的包名，参数二：标记,获取什么数据就给什么标记，给0，只获取最基本信息
				try {
					PackageInfo packageInfo = packageManager.getPackageInfo(packageName, 0);
					int versionCode = packageInfo.versionCode;
					return versionCode;
				} catch (NameNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
				return 1;
	}
}
